<template>
  <a-form-item label="回调地址">
    <div class="flex">
      <a-input
        class="inline-block"
        v-model="text"
        placeholder="请输入"
        :disabled="!editable"
      />
      <a-button
        type="link"
        v-if="!editable"
        icon="edit"
        @click="$emit('on-edit')"
      >
        编辑
      </a-button>
      <a-button v-else class="ml-4" type="link" icon="save" @click="save">
        保存
      </a-button>
    </div>
  </a-form-item>
</template>

<script>
// import thisTable from './table'
// import editModal from './modal-edit.vue'
// import addModal from './modal-add.vue'

export default {
  props: ['value'],
  // components: { editModal, addModal },
  data() {
    return {
      editable: false,
      text: '',
    }
  },
  created() {
    this.text = this.value
  },
  methods: {
    save() {
      this.axios.put('/s/notify_url', { text: this.text }).then((res) => {
        if (res.data.code !== 1) {
          this.$message.error('输入格式错误')
          return
        }
        this.$emit('input', this.text)

        let user = this.$store.state.account.user
        user.notify_url = this.text
        this.$store.commit('account/setUser', user)

        this.$message.success('设置成功')
        this.editable = false
      })
    },
  },
}
</script>

